home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#25 (Oct 87)
/
Forth MiniTerm source
/
Miniterm.edit
< prev
Wrap
Text File
|
1987-09-18
|
8KB
|
359 lines
\ routines for hierarchical menu support in Mach2
\ J. Langowski / MacTutor July 1987
only forth also assembler also mac also i/o
108 USER TaskMenuBar
164 USER goaway-hook
$4D444546 CONSTANT "mdef
$44525652 CONSTANT "drvr
$28E CONSTANT ROM85
$B5C CONSTANT MenuMgrType
$A89F CONSTANT undefTrap
( *** menu record data structure *** )
0 CONSTANT menuID ( integer )
2 CONSTANT menuWidth ( integer )
4 CONSTANT menuHeight ( integer )
6 CONSTANT menuProc ( handle )
10 CONSTANT enableFlags ( longint )
14 CONSTANT menuData ( Str255 and other data )
( *** menu Data format *** )
( counted string: menu title )
( followed by 1 to 31 times: )
( counted string: menu item )
( byte: item icon # )
( byte: equivalent character )
( byte: check mark character )
( byte: text attributes )
( .... )
( end: zero byte. )
CODE setitemcmd
EXG D4,A7
MOVE.L 8(A6),-(A7)
MOVE.W 6(A6),-(A7)
MOVE.W 2(A6),-(A7)
ADDA.W #$C,A6
_setItemCmd
EXG D4,A7
RTS
END-CODE
CODE getitemcmd
EXG D4,A7
MOVE.L 8(A6),-(A7)
MOVE.W 6(A6),-(A7)
MOVE.L (A6),-(A7)
ADDA.W #$C,A6
_getItemCmd
EXG D4,A7
RTS
END-CODE
: newrom? rom85 w@ l_ext 0> ;
: newmenus? MenuMgrType @ -1 <> ;
: getItemCmd?
$A84E call gettrapaddress undefTrap call gettrapaddress <> ;
: MDEF-version "mdef 0 call getresource @ 10 + w@ ;
: branch.menu { subID mainID item# | mainmenu submenu -- }
newrom?
newmenus? AND
getItemCmd? AND
MDEF-version 9 > AND
IF mainID call getMHandle -> mainmenu
mainmenu 0= abort" Main menu does not exist"
subID call getMHandle -> submenu
submenu 0= abort" Submenu does not exist"
mainmenu item# subID call setitmmark
mainmenu item# $1B setItemCmd
ELSE
1 abort" System does not support hierarchical menus"
THEN
;
Variable baud#
Variable data#
Variable stop#
Variable parity#
Variable hsk#
Variable DAName
400 8000 terminal EMULATOR
NEW.WINDOW TERM
" Terminal" TERM TITLE
45 25 335 475 TERM BOUNDS
DOCUMENT VISIBLE GROWBOX CLOSEBOX TERM ITEMS
NEW.MBAR TermMenuBar
200 CONSTANT Apple_ID
create apple_string $01 c, $14 c,
NEW.MENU Apple_menu
apple_string Apple_menu TITLE
0 200 Apple_menu BOUNDS
" About Terminal…;(-" Apple_menu ITEMS
300 CONSTANT Term_ID
NEW.MENU Term_menu
" Terminal" Term_menu TITLE
0 Term_ID Term_menu BOUNDS
" Rate;Format;Parity;Handshake;Quit" Term_menu ITEMS
129 CONSTANT baud_ID
NEW.MENU baud_menu
" Rate" baud_menu TITLE
-1 baud_ID baud_menu BOUNDS \ insert as hierarchical menu
" 300;600;1200;1800;2400;3600;4800;7200;9600;19200" baud_menu ITEMS
130 CONSTANT form_ID
NEW.MENU form_menu
" Format" form_menu TITLE
-1 form_ID form_menu BOUNDS \ insert as hierarchical menu
" 5 data;6 data;7 data;8 data;(-;1 stop;1.5 stop;2 stop" form_menu ITEMS
131 CONSTANT parity_ID
NEW.MENU parity_menu
" Parity" parity_menu TITLE
-1 parity_ID parity_menu BOUNDS \ insert as hierarchical menu
" none;odd;even" parity_menu ITEMS
132 CONSTANT hsk_ID
NEW.MENU hsk_menu
" Handshake" hsk_menu TITLE
-1 hsk_ID hsk_menu BOUNDS \ insert as hierarchical menu
" none;xon-xoff;cts" hsk_menu ITEMS
: do.config
baud# @ CASE
1 OF $17C ENDOF
2 OF $BD ENDOF
3 OF $5E ENDOF
4 OF $3E ENDOF
5 OF $2E ENDOF
6 OF $1E ENDOF
7 OF $16 ENDOF
8 OF $E ENDOF
9 OF $A ENDOF
10 OF $4 ENDOF
ENDCASE
data# @ CASE
1 OF $0 ENDOF
2 OF $800 ENDOF
3 OF $400 ENDOF
4 OF $C00 ENDOF
ENDCASE
+
stop# @ CASE
6 OF $4000 ENDOF
7 OF $8000 ENDOF
8 OF $C000 ENDOF
ENDCASE
+
parity# @ CASE
1 OF $0 ENDOF
2 OF $1000 ENDOF
3 OF $3000 ENDOF
ENDCASE
+
hsk# @ CASE
1 OF $0 ENDOF
2 OF $10000 ENDOF
3 OF $20000 ENDOF
ENDCASE
+
comm1 MODE IF 10 call sysbeep THEN
;
: init.menus
TermMenuBar ADD
TermMenuBar Apple_menu ADD
Apple_menu @ "drvr CALL AddResMenu
TermMenuBar term_menu ADD
TermMenuBar baud_menu ADD
TermMenuBar form_menu ADD
TermMenuBar parity_menu ADD
TermMenuBar hsk_menu ADD
baud_ID term_ID 1 branch.menu
form_ID term_ID 2 branch.menu
parity_ID term_ID 3 branch.menu
hsk_ID term_ID 4 branch.menu
baud_menu @ 9 -1 call checkitem
form_menu @ 4 -1 call checkitem
form_menu @ 8 -1 call checkitem
parity_menu @ 1 -1 call checkitem
hsk_menu @ 1 -1 call checkitem
9 baud# !
4 data# ! 8 stop# !
1 parity# ! 1 hsk# !
do.config
;
: do.about 128 0 CALL alert drop ;
: do.apple { item# }
\ item# = 1 (About...)?
item# 1 =
IF do.about
ELSE
Apple_menu @ item# DAName CALL GetItem
DAName CALL OpenDeskAcc DROP
THEN ;
: do.baud
baud_menu @ over -1 call checkitem
baud_menu @ baud# @ 0 call checkitem
baud# !
;
: do.format
form_menu @ over -1 call checkitem
dup 5 < IF
form_menu @ data# @ 0 call checkitem
data# !
ELSE
form_menu @ stop# @ 0 call checkitem
stop# !
THEN
;
: do.parity
parity_menu @ over -1 call checkitem
parity_menu @ parity# @ 0 call checkitem
parity# !
;
: do.hshake
hsk_menu @ over -1 call checkitem
hsk_menu @ hsk# @ 0 call checkitem
hsk# !
;
: do.term
CASE
5 OF bye ENDOF
ENDCASE
;
: termmenuhandler ( item# menuID -- )
CASE
apple_ID OF do.apple ENDOF
baud_ID OF do.baud ENDOF
form_ID OF do.format ENDOF
parity_ID OF do.parity ENDOF
hsk_ID OF do.hshake ENDOF
term_ID OF do.term ENDOF
ENDCASE
do.config
0 call hilitemenu
;
( terminal emulator code from PAS starts here )
$0A CONSTANT LINE_FEED ( ascii 'linefeed' )
$20 CONSTANT SP ( ascii 'space' )
$14 CONSTANT ctrl-t
VARIABLE inputbuffer
64 VALLOT ( 68 bytes for holding modem input)
: emit>console ( n - ) ( send a single character to the screen )
CONSOLE OUTPUT
EMIT ;
: emit>modem ( n - ) ( send a single character to the modem port)
COMM1 OUTPUT
EMIT ;
: ?comm1 ( - n ) ( this word will determine if the Modem Port )
COMM1 INPUT ( has received any characters. The number returned )
?TERMINAL ; ( will indicate the number of characters waiting. )
: @comm1 ( - n ) ( this word will read one character from the )
COMM1 INPUT ( modem port. If no characters are ready, this )
KEY ; ( word will wait. The task will be put to sleep )
( and awaken when the ioCompletion routine is )
( executed upon receiving a character. )
( type>screen is an enhanced version of the normal TYPE routine. )
( this word will filter out linefeeds. A linefeed is printed on )
( the Macintosh as a square box. )
: type>screen { address length }
length 0 DO
address I + C@ ( throw away 8th bit )
$7F AND
address I + C!
address I + C@ LINE_FEED = ( look for a Linefeed)
IF
sp address I + C! ( replace LF with SP)
THEN
LOOP
CONSOLE OUTPUT
address length TYPE ; ( type out the modified string)
: monitor-modem { | temp }
?comm1 ( how many characters are ready ? )
?DUP ( Note: The maximum # of chars must be)
( less than 64. This is the default size)
( of the Serial Driver buffer. )
IF
-> temp ( save number of unread characters )
COMM1 INPUT
inputbuffer temp EXPECT ( receive characters from modem)
inputbuffer temp type>screen ( send this string to screen)
THEN ;
: goaway-handler bye ;
: PopUp ( - )
Term dup CALL showwindow CALL selectwindow ;
: start-comm
ACTIVATE ( assign the following code to EMULATOR )
['] termmenuhandler menu-vector !
['] goaway-handler goaway-hook !
Popup
termmenubar @ call setmenubar call drawmenubar
CLS
CONSOLE OUTPUT ." Ready >" CR
BEGIN
CONSOLE INPUT
?TERMINAL ( has the user pressed a key ? )
IF
KEY emit>modem ( send char to modem. 'no local echo' )
THEN
monitor-modem ( watch the serial port)
AGAIN
;
: MODEM
term ADD ( make the term window )
term EMULATOR BUILD ( tie the term window
to the EMULATOR task )
init.menus
TermMenuBar emulator mbar>task
EMULATOR start-comm ; ( launch task )